<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    //protected $dateFormat = 'U';
    protected $fillable = [
        'name',
        'phone',
        'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'remember_token',
    ];

    // 我的地址
    public function addresses()
    {
        return $this->hasMany(UserAddress::class);
    }

    /**
     * 渠道用户信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function channel()
    {
        return $this->belongsTo(UserChannel::class, 'user_channelid');
    }

    // 我的订单
    public function orders()
    {
        return $this->hasMany(Order::class, 'user_id');
    }

    // 我的卡券
    public function coupons()
    {
        return $this->hasMany(UserCoupon::class, 'user_id');
    }

    // 购物车内容
    public function cartItems()
    {
        return $this->hasOne(CartItem::class);
    }

    // 微信授权信息
    public function wechat()
    {
        return $this->hasOne(WechatUser::class, 'user_id');
    }
}
